#include "StdAfx.h"
#include "Point3D.h"

CPoint3D::CPoint3D(void)
: x (0.f)
, y (0.f)
, z (0.f)
{
}
CPoint3D::CPoint3D(const CPoint3D& p)
: x (p.x)
, y (p.y)
, z (p.z)
{
}
CPoint3D::CPoint3D(float _x,float _y,float _z)
: x (_x)
, y (_y)
, z (_z)
{
}
CPoint3D::~CPoint3D(void)
{
}

float CPoint3D::Normalize()
{
	float L = Length();		
	x /= L;
	y /= L;
	z /= L;
	return L;
}
float CPoint3D::Length()
{
	return sqrt(x*x + y*y + z*z);
}
float CPoint3D::Distance(const CPoint3D& p)
{
	CPoint3D v = (*this - p);
	return v.Length();
}
float CPoint3D::Dot(const CPoint3D& p)
{
	return (x*p.x + y*p.y + z*p.z);
}
CPoint3D CPoint3D::Cross(const CPoint3D& p)
{
	CPoint3D n;
	n.x = y*p.z - z*p.y;
	n.y = z*p.x - x*p.z;
	n.z = x*p.y - y*p.x;
	return n;
}

CPoint3D CPoint3D::operator+(const CPoint3D& p)
{
	return CPoint3D(x + p.x, y + p.y, z + p.z);
}
CPoint3D CPoint3D::operator-(const CPoint3D& p)
{
	return CPoint3D(x - p.x, y - p.y, z - p.z);
}
CPoint3D CPoint3D::operator*(float f)
{
	return CPoint3D(x*f,y*f,z*f);
}
CPoint3D CPoint3D::operator/(float f)
{
	return CPoint3D(x/f,y/f,z/f);
}
bool CPoint3D::operator==(const CPoint3D& p)
{
	return (fabs(x - p.x) < EPSILON
		&&  fabs(y - p.y) < EPSILON 
		&&  fabs(z - p.z) < EPSILON);
}
bool CPoint3D::operator!=(const CPoint3D& p)
{
	return !(*this == p);
}
void CPoint3D::operator+=(const CPoint3D& p)
{
	x+=p.x;
	y+=p.y;
	z+=p.z;
}
void CPoint3D::operator-=(const CPoint3D& p)
{
	x-=p.x;
	y-=p.y;
	z-=p.z;
}
void CPoint3D::operator*=(float f)
{
	x*=f;
	y*=f;
	z*=f;
}
void CPoint3D::operator/=(float f)
{
	x/=f;
	y/=f;
	z/=f;
}
CPoint3D CPoint3D::operator-()
{	
	return CPoint3D(-x,-y,-z);
}